using System;
using System.Web.UI.WebControls;

using Geekees.App.Cashbook.Lib.BLL;

namespace Geekees.App.Cashbook.Lib.Helper
{
	/// <summary>
	/// Summary description for Binder.
	/// </summary>
	public class Binder
	{
		public Binder()
		{
			
		}

		public static void BindClassification( ListControl list, ListPromptType type  )
		{
			list.DataSource= BLClassification.GetAllClassification();
			list.DataTextField = "Name";
			list.DataValueField = "ID";

			list.DataBind();
			AddPrompt( list, type );
		}

		public static void BindCategory( ListControl list, int classificationId,  ListPromptType type  )
		{
			list.DataSource= BLCategory.GetCategoryByClassificationId( classificationId );
			list.DataTextField = "Name";
			list.DataValueField = "ID";

			list.DataBind();
			AddPrompt( list, type );
		}

		public static void BindCategory( ListControl list, ListPromptType type  )
		{
			list.DataSource= BLCategory.GetAllCategory( );
			list.DataTextField = "Name";
			list.DataValueField = "ID";

			list.DataBind();
			AddPrompt( list, type );
		}

		public static void AddPrompt( ListControl list, ListPromptType type)
		{
			switch( type )
			{
				case ListPromptType.Add:
					list.Items.Insert( 0 , new ListItem( "Add new one", ListPromptType.Add.ToString() ));
					break;
				case ListPromptType.Select:
					list.Items.Insert( 0 , new ListItem( "Select one", ListPromptType.Select.ToString() ));
					break;
				case ListPromptType.All:
					list.Items.Insert( 0 , new ListItem( "All", ListPromptType.Select.ToString() ));
					break;
				case ListPromptType.None:
					break;
			}
		}
	}

	public enum ListPromptType
	{
		Add, Select, All, None
	}
}
